local yiqi = fk.CreateSkill{
  name = "hanqing__yiqi",
}

Fk:loadTranslationTable{
  ["hanqing__yiqi"] = "刈旗",
  [":hanqing__yiqi"] = "准备阶段或结束阶段，你可以视为使用一张“披矢”牌，若此牌造成伤害，你弃置之。",

  ["#hanqing__yiqi-use"] = "刈旗：你可以视为使用一张“披矢”牌，若造成伤害则弃置之",
}

yiqi:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yiqi.name) and
      (player.phase == Player.Start or player.phase == Player.Finish) and
      table.find(player:getPile("hanqing__pishi"), function (id)
        return player:canUse(Fk:cloneCard(Fk:getCardById(id).name), { bypass_times = true })
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseRealCard(player, {
      pattern = player:getPile("hanqing__pishi"),
      skill_name = yiqi.name,
      prompt = "#hanqing__yiqi-use",
      cancelable = true,
      extra_data = {
        bypass_times = true,
        extraUse = true,
        expand_pile = player:getPile("hanqing__pishi"),
      },
      skip = true,
    })
    if use then
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).extra_data
    local id = use.card.id
    local card = Fk:cloneCard(use.card.name)
    card.skillName = yiqi.name
    use.card = card
    room:useCard(use)
    if use.damageDealt and not player.dead and table.contains(player:getPile("hanqing__pishi"), id) then
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, yiqi.name, nil, true, player)
    end
  end,
})

return yiqi
